package com.my.plugin.tools;


/**
 * 这是分页的内容
 * 
 * @author YH
 *
 */
public class Page {
	private long countSize;// 总记录
	private long countPage;// 总页数
	private long currentPage;// 当前页
	private long upPage;// 上一页
	private long downPage;// 下一页
	private long lastPage;// 最后一页
	private final long firstPage = 1;// 第一页
	private long size;// 每页的数量
	private long index;// 开始的索引

	/**
	 * 构造一个分页的对象
	 * 
	 * @param currentPage
	 *            当前页
	 * @param size
	 *            每页的数量
	 */
	public Page(long currentPage, long size) {
		super();
		this.currentPage = currentPage;
		this.size = size;
	}
	
	

	public Page() {
		super();
	}



	/**
	 * 获得总记录数
	 * 
	 * @return
	 */
	public long getCountSize() {
		return countSize;
	}

	/**
	 * 设置总记录数
	 * 
	 * @param countSize
	 */
	public void setCountSize(long countSize) {
		this.countSize = countSize;
	}

	/**
	 * 获得总页数
	 * 
	 * @return
	 */
	public long getCountPage() {
		countPage = ((getCountSize() - 1) / getSize()) + 1;
		return countPage;
	}

	/**
	 * 获得当前页
	 * 
	 * @return
	 */
	public long getCurrentPage() {
		if (currentPage < 1) {
			currentPage = 1;

		} else if (currentPage > getCountPage()) {
			currentPage = getCountPage();
		}

		return currentPage;

	}

	/**
	 * 设置当前页
	 * 
	 * @param currentPage
	 */
	public void setCurrentPage(long currentPage) {
		this.currentPage = currentPage;
	}

	/**
	 * 获得上一页
	 * 
	 * @return
	 */
	public long getUpPage() {
		upPage = getCurrentPage() - 1 >= 1 ? getCurrentPage() - 1 : 1;
		return upPage;
	}

	/**
	 * 获得下一页
	 * 
	 * @return
	 */
	public long getDownPage() {
		downPage = getCurrentPage() + 1 <= getCountPage() ? getCurrentPage() + 1 : getCountPage();
		return downPage;
	}

	/**
	 * 获得最后一页
	 * 
	 * @return
	 */
	public long getLastPage() {
		lastPage = getCountPage();
		return lastPage;
	}

	/**
	 * 获得每页的数量
	 * 
	 * @return
	 */
	public long getSize() {
		return size;
	}

	/**
	 * 设置每页的数量
	 * 
	 * @param size
	 */
	public void setSize(long size) {
		this.size = size;
	}

	/**
	 * 获得第一页
	 * 
	 * @return
	 */
	public long getFirstPage() {
		return firstPage;
	}

	/**
	 * 获得本页索引
	 * 
	 * @return 索引
	 */
	public long getIndex() {
		index = (getCurrentPage() - 1) * getSize();
		return index;
	}

	@Override
	public String toString() {
		return "Page [countSize=" + countSize + ", countPage=" + countPage + ", currentPage=" + currentPage
				+ ", upPage=" + upPage + ", downPage=" + downPage + ", lastPage=" + lastPage + ", firstPage="
				+ firstPage + ", size=" + size + ", index=" + index + "]";
	}
	
	

}
